/**
 * Created by 121 on 2016/4/08.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog',
    'calendar',
    'highCharts'
], function ($, common, ready, template, Collection, Model, dialog, calendar, highCharts) {
    var index = function () {
        this.init();
    };
    $('.sidebar').css({'display':'none'});
    $('header').css({'display':'none'});
    $('.main').css({'margin':'50px 50px'});
    index.prototype = {
        init: function () {
            this.event();
            //this.fetch();
        },
        event: function () {
            var _this = this;
            var amount = function () {
                var ids='9,4,7,1,8';
                $.ajax({
                    url: _global.url.api + 'week_data_report',
                    type: 'get',
                    data: {ids: ids},
                    success: function (res) {
                        $('#amount-data-success').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: ''
                            },
                            xAxis: [{
                                tickInterval: res.data.tickInterval,
                                showFirstLabel: res.data.showFirstLabel,
                                categories: res.data.tab,
                                title: {
                                    text: res.data.title_x,
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                labels: {
                                    rotation: -45,
                                    align: 'right',
                                    style: {
                                        fontSize: '10px'
                                    }
                                }
                            }],
                            yAxis: [{ // Primary yAxis
                                allowDecimals: false,
                                floor: 0,
                                labels: {
                                    format: '{value}',
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                title: {
                                    text: '',
                                    style: {
                                        color: '#89A54E'
                                    }
                                }
                            }],
                            tooltip: {
                                shared: true
                            },
                            legend: {
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle',
                                backgroundColor: '#FFFFFF'
                            },
                            series: res.data.series

                        });
                        $('#amount_list').html(template('data-item', {'data': res.data.tab}));
                        $('#amount-list').html(template('amount-item', {'data': res.data.series}))
                    }

                });

            };

            var device = function () {
                var ids='12,11,13,15,14,16';
                $.ajax({
                    url: _global.url.api + 'week_data_report',
                    type: 'get',
                    data: {ids: ids},
                    success: function (res) {
                        $('#device-data-success').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: ''
                            },
                            xAxis: [{
                                tickInterval: res.data.tickInterval,
                                showFirstLabel: res.data.showFirstLabel,
                                categories: res.data.tab,
                                title: {
                                    text: res.data.title_x,
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                labels: {
                                    rotation: -45,
                                    align: 'right',
                                    style: {
                                        fontSize: '10px'
                                    }
                                }
                            }],
                            yAxis: [{ // Primary yAxis
                                allowDecimals: false,
                                floor: 0,
                                labels: {
                                    format: '{value}',
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                title: {
                                    text: '',
                                    style: {
                                        color: '#89A54E'
                                    }
                                }
                            }],
                            tooltip: {
                                shared: true
                            },
                            legend: {
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle',
                                backgroundColor: '#FFFFFF'
                            },
                            series: res.data.series

                        });console.log(res.data.tab);
                        $('#device_list').html(template('data-item', {'data': res.data.tab}));
                        $('#device-list').html(template('amount-item', {'data': res.data.series}))
                    }

                });

            };
            var register = function () {
                var ids='3,6,2';
                $.ajax({
                    url: _global.url.api + 'week_data_report',
                    type: 'get',
                    data: {ids: ids},
                    success: function (res) {
                        $('#register-data-success').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: ''
                            },
                            xAxis: [{
                                tickInterval: res.data.tickInterval,
                                showFirstLabel: res.data.showFirstLabel,
                                categories: res.data.tab,
                                title: {
                                    text: res.data.title_x,
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                labels: {
                                    rotation: -45,
                                    align: 'right',
                                    style: {
                                        fontSize: '10px'
                                    }
                                }
                            }],
                            yAxis: [{ // Primary yAxis
                                allowDecimals: false,
                                floor: 0,
                                labels: {
                                    format: '{value}',
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                title: {
                                    text: '',
                                    style: {
                                        color: '#89A54E'
                                    }
                                }
                            }],
                            tooltip: {
                                shared: true
                            },
                            legend: {
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle',
                                backgroundColor: '#FFFFFF'
                            },
                            series: res.data.series

                        });
                        $('#register_list').html(template('data-item', {'data': res.data.tab}));
                        $('#register-list').html(template('amount-item', {'data': res.data.series}))
                    }

                });

            };
            var active_rate = function () {
                var ids='5';
                $.ajax({
                    url: _global.url.api + 'week_data_report',
                    type: 'get',
                    data: {ids: ids},
                    success: function (res) {
                        $('#active_rate-data-success').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: ''
                            },
                            xAxis: [{
                                tickInterval: res.data.tickInterval,
                                showFirstLabel: res.data.showFirstLabel,
                                categories: res.data.tab,
                                title: {
                                    text: res.data.title_x,
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                labels: {
                                    rotation: -45,
                                    align: 'right',
                                    style: {
                                        fontSize: '10px'
                                    }
                                }
                            }],
                            yAxis: [{ // Primary yAxis
                                allowDecimals: false,
                                floor: 0,
                                labels: {
                                    format: '{value}',
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                title: {
                                    text: '',
                                    style: {
                                        color: '#89A54E'
                                    }
                                }
                            }],
                            tooltip: {
                                shared: true
                            },
                            legend: {
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle',
                                backgroundColor: '#FFFFFF'
                            },
                            series: res.data.series

                        });
                        $('#active_rate_list').html(template('data-item', {'data': res.data.tab}));
                        $('#active_rate-list').html(template('amount-item', {'data': res.data.series}))
                    }

                });

            };




            amount();
            device();
            register();
            active_rate();
            /*    fail();
             fail_reasons();*/

        }
    };
    new index();
});